import { HTTP } from "../utils/http.js"

class UserModel extends HTTP {
  fetch( _callback) {
    this.request({
      url: "/usr/personInf",
      method: "POST",
      success: function (data) {
        let userInfo = data[0];
        _callback(userInfo);
      }
    })
  }
  updateIntroduce(message,label,_callback){
   let data =  {
      "UsrIntroduction": message,
      "UsrLabelArray":label
    }

    this.request({
      url: "/usr/updateUsrIntroduction",
      method: "POST",
      data:data,
      success: function (data) {
        _callback(data);
      }
    })
  }

  getLabel(_callback){
    this.request({
      url: "/sys/getsyslabel",
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    })
  }

  auth(data,_callback){
    this.request({
      url: "/usr/applyAuthentication",
      method: "POST",
      data:data,
      success: function (data) {
        _callback(data);
      }
    })
  }
  addEdu(data,_callback){
     this.request({
      url: "/usr/addEducationalExperience",
      data: data,
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    })
  }
  updateEdu(data, _callback) {
    this.request({
      url: "/usr/updateAddEducationalExperience",
      data: data,
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    })
  }
  getEduForRealName(_callback){
    this.request({
      url: "/usr/educationalExperience",
      method: "POST",
      success: function (data) {
          data.forEach(function(item,index){
            if(item.useForRealName=='1'){
              _callback(item);
            }
          })
      }
    });
  }

  getUsrMessage(_callback){
    // "messageStatus":"0"  0-未读 1-已读 2-忽略 3-已处理}
    let data = {
      "messageStatus":"0"
    }
    this.request({
      url: "/usr/GetUsrMessage",
      method: "POST",
      data:data,
      success: function (data) {
        _callback(data);
      }
    });
  }
  getUsrMessageWithPagenation(pagenation,_callback) {
    // "messageStatus":"0"  0-未读 1-已读 2-忽略 3-已处理}
    let data = {
      "messageStatus": "0"
    }
    this.request({
      url: "/usr/GetUsrMessage?pageSize=" + pagenation.pageSize + "&pageNum=" + pagenation.pageNum,
      method: "POST",
      data: data,
      success: function (data) {
        _callback(data);
      }
    });
  }
  updateUsrMessageStat(params,_callback) {
    //{"isRead":"0"    说明 0-未读 1-已读 空-查询全部}
    this.request({
      url: "/usr/updateUsrMessageStat",
      data:params,
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    });
  }


  handleFriendRequest(params, _callback) {
    let data = {"friendId": params}
    this.request({
      url: "/usr/handleFriendRequest",
      data: data,
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    });
  }

  handleAuthentication(params, _callback) {
    let data = params
    this.request({
      url: "/usr/handleAuthentication",
      data: data,
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    });
  }


  getPoints( _callback) {
    this.request({
      url: "/usr/pointshistory",
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    });
  }
  myInvite(_callback) {
    this.request({
      url: "/usr/myinvitationlist",
      method: "POST",
      success: function (data) {
        _callback(data);
      }
    });
  }
}

export { UserModel }